
/********************************************************
Code to create the predicted probabilities for Figure OE4. 
Also creates the Table for these reults. 
Plotting is done using R. 
***********************************************************/

/******************************************************
Pew/CNN
********************************************************/

/**************************
		Data
**************************/

clear
*change directory to "....\Data\"
*cd 
use "pew_cnn_comb.dta"


/**************************
		Cleaning

Some of the labels are not right 
**************************/

**Income
label def inc1 1 "<30,000" 2 "30,000-49,999" 3 "50,000-74,999" 4 "75,000-99,999" 5 "100,000+"
label values income1 inc1
label var income1 "Income"

label def inc2 1 "<30,000" 2 "30,000-49,999" 3 "50,000-74,999" 4 "75,000+"
label values income2 inc2
label var income2 "Income"

**Gender
label def gend 1 "Female" 0 "Male"
label values gender gend
label var gender "Gender"

**Education 
label var educ "Education"
label def edu 1 "<HS" 2 "HS" 3 "Some College" 4 "BA" 5 "Post-BA"
label values educ edu

**Race/Ethnicity
*Remove the 9
recode race_eth (9 = .)
label var race_eth "Race/Ethnicity"
label def rac 1 "White" 2 "Black" 3 "Hispanic" 4 "Other Race"
label values race_eth rac

**Age
label var age "Age"

**Sponsor
encode sponsor, gen(sponsor1)

**Year
label var year "Year of Survey"

**Too Extreme
label var too_extreme1 "Parties Too Extreme?"
label def too1 1 "Neither" 2 "One Too Extreme" 3 "Both Too Extreme"
label values too_extreme1  too1

***PID & Ideol Ext
label var pid_ext "PID Extremity"
label def pext 1 "Independent" 2 "Leaner" 3 "Partisan"
label values pid_ext pext

label var ideol_ext "Ideological Extremity"
label def iext 1 "Moderate" 2 "Liberal/Conservative" 3 "Very Liberal/Conservative"
label values ideol_ext iext

**Too Extreme (no dks)
gen dks = 1 if rep_dk == 0 & dem_dk == 0 

gen tooext_nodk = . 
	replace tooext_nodk = 1 if too_extreme1 == 1 & dks == 1
	replace tooext_nodk = 2 if too_extreme1 == 2 & dks == 1
	replace tooext_nodk = 3 if too_extreme1 == 3 & dks == 1
label var tooext_nodk "Parties Too Extreme?" 
label values tooext_nodk too1


/**************************
	Model and Predictions
**************************/


eststo clear
eststo: gsem (i.tooext_nodk <- i.pid_ext i.ideol_ext i.gender i.race_eth c.age i.income1 i.educ year sponsor1 S[surveyid]@1) [pweight=weight], mlogit
	
	forval i = 1/3 {
	margins pid_ext ideol_ext, predict(outcome(`i'.tooext_nodk)) saving(probs_`i'_nodk, replace)
	}
	

*Table
esttab using "table_oe2_pewcnn.rtf", replace onecell se bic label nobaselevels unstack b(3) ///
	mtitles("Neither" "One Party" "Both Parties") ///
	title("{\b Table OE2:} Is the Party Sytem Too Extreme? (Pew & CNN; Weighted; No DKs)")
	
/****************************************************
Lucid
*****************************************************/


clear
use "lucid_coded_all.dta"
set more off 



/**************************
		Cleaning

Some of the labels are not right 
**************************/


****PID Strength/Extremity
label var pid_ext "PID Extremity"
label def piext 1 "Independent" 2 "Leaner" 3 "Not Very Strong Partisan" 4 "Strong Partisan"
label values pid_ext piext

label var pid_idstr_1 "PID ID Strength"

****Ideology
*Symbolic
label var ideol_ext "Ideological Extremity"
label def iext 1 "Moderate" 2 "Closer Lib/Con"  3 "Somewhat Lib/Con" 4 "Very Lib/Con"
label values ideol_ext iext

****Issue Consistency
label var op_ideol_cons "Issue Consistency"

*Operational
label var op_ideol "Operational Ideology"

****Political Knowledge
label var knowl_sum "Political Knowledge"

****Opinionation
label var opinionation "Opinionation"

****Demographics
*Age
label var age "Age"

*Gender
label var gender "Gender"

*Race
label def rac 1 "White" 2 "Black" 3 "Hispanic" 4 "Asian" 5 "Other Race"
label values race_eth rac
label var race_eth "Race/Ethnicity"

*Education
label def edu 1 "<HS" 2 "HS" 3 "Some College" 4 "BA" 5 "BA+"
label values educ edu

*Income
label var house_income "Income"

*Weight
label var weight "Raked Survey Weight"

*Too Extreme
label var too_extreme_1 "Parties Too Extreme?"
label def tooext 1 "Neither Party" 2 "One Party" 3 "Both Parties"
label values too_extreme_1 tooext

*Perceived Policy Distance
gen ppd = abs(abs(self_ideol-dem_ideol)-abs(self_ideol-rep_ideol))
label var ppd "Perceived Policy Distance"

*Too Extreme, No DKS
gen tooext_nodk = . 
	replace tooext_nodk = 1 if rep_extreme == 2 & dem_extreme == 2
	replace tooext_nodk = 2 if rep_extreme == 1 & dem_extreme == 2
	replace tooext_nodk = 2 if rep_extreme == 2 & dem_extreme == 1
	replace tooext_nodk = 3 if rep_extreme == 1 & dem_extreme == 1
label values tooext_nodk tooext
	
	
*DKs
recode rep_extreme dem_extreme (1 2 = 0) (3 = 1), gen(rep_dk dem_dk)

gen dks = . 
	replace dks = 1 if dem_dk == 0 & rep_dk == 0
	replace dks = 2 if dem_dk == 1 & rep_dk == 0
	replace dks = 2 if dem_dk == 0 & rep_dk == 1 
	replace dks = 3 if dem_dk == 1 & rep_dk == 1
label def dk_lab 1 "No DK" 2 "One DK" 3 "Both DK"
label values dks dk_lab

********************/
	
***PID Strength
eststo clear
eststo: mlogit tooext_nodk c.pid_idstr_all i.ideol_ext op_ideol_cons ppd knowl_sum opinionation c.age house_income i.gender i.race_eth i.educ , base(1)
		
		*Probabilities
			margins ideol_ext, saving(lucid_sym_nodk, replace)
			margins, at(op_ideol_cons=(0(1)5)) saving(lucid_op_nodk, replace)
			margins, at(ppd=(0(1)6)) saving(lucid_ppd_nodk, replace)	
			margins, at(pid_idstr_all=(1(1)4)) saving(lucid_pid_nodk, replace)
		
*Table
esttab using "table_oe3_lucid_results.rtf", replace onecell se bic label nobaselevels unstack ///
	title("{\b Table OE3:} Is the Party Sytem Too Extreme? (Lucid; No DKs)") pr2
	
	